﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.SharePoint.Explorer;
using System.Drawing;

namespace SPVSX.Explorer.Extensions
{
    /// <summary>
    /// Represents an extension of SharePoint site nodes in Server Explorer for custom actions. 
    /// </summary>
    // Enables Visual Studio to discover and load this extension.
    [Export(typeof(IExplorerNodeTypeExtension))]
    // Indicates that this class extends SharePoint site nodes in Server Explorer.
    [ExplorerNodeType(ExplorerNodeTypes.GenericFolderNode)]
    partial class GenericFolderNodeExtension : IExplorerNodeTypeExtension
    {
        public void Initialize(IExplorerNodeType nodeType)
        {
            //Initialise the extensions
            InitializeThemeGallery(nodeType);
            InitializeWebPartGallery(nodeType);
        }

        #region Helpers

        public static IExplorerNode Create(IExplorerNode parentNode, string text, Action<IExplorerNode> createChildNodes)
        {
            Dictionary<object, object> annotations = null;
            if (createChildNodes != null)
            {
                Dictionary<object, object> dictionary2 = new Dictionary<object, object>();
                dictionary2.Add("CreateChildNodes", createChildNodes);
                annotations = dictionary2;
            }
            return Create(parentNode, text, annotations);
        }

        public static IExplorerNode Create(IExplorerNode parentNode, string text, IDictionary<object, object> annotations)
        {
            return parentNode.ChildNodes.Add(WebPartGalleryNodeTypeProvider.WebPartGalleryNodeTypeId, text, annotations);
        }

        public static IExplorerNode Create(IExplorerNode parentNode, string text, Image folderIcon, Action<IExplorerNode> createChildNodes)
        {
            IExplorerNode node = Create(parentNode, text, createChildNodes);
            node.Icon = folderIcon;
            return node;
        }

        #endregion
    }
}
